﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using ModelLayer;
using AssessmentTool.PresentationLogic.Controllers;

namespace AssessmentTool
{
	public partial class RadioChoose : UserControl
	{
        
        private static Color[] ANIMATION_COLORS = { Color.FromArgb(255, 173, 33, 33), Color.FromArgb(255, 251, 242, 17), Color.FromArgb(255, 251, 242, 17), Color.FromArgb(255, 16, 243, 30) };

        private static Dictionary<String,double> yValue=new Dictionary<string,double>() {{"Nessuna",15},{"Base",45},{"Buona",75},{"Profonda",105}};
       
        private String descrizioneValoreScelto = "";
        private double yScelto;
        private RadioChooseController controller;
       

		public RadioChoose()
		{
			// Required to initialize variables
			InitializeComponent();
            comment.Visibility = Visibility.Collapsed;
            controller = new RadioChooseController(this);
		}

        public void initWithCompetenza(ModelLayer.Competenza comp,Competenza guiController)
        {
            controller.initWithCompetenza(comp,guiController);

        }

        public void cambioColoreAnimation(double to,Color color)
        {
            AnimazioneLunghezza.From = barraColore.Width;
            AnimazioneLunghezza.To = to;
            AnimazioneColoreTo.Value = color;
            
            CambioColore.Stop();
            CambioColore.Begin();
        }

        public void cambioColore(int indice, String nome, bool animation)
        {
            comment.Visibility = Visibility.Visible;
            double to = (30 * indice) + 30;
            Color color = ANIMATION_COLORS[indice];
            descrizioneValoreScelto = nome;
            yScelto = yValue[nome];
            comment.AnchorPointY = yScelto+"";
            
            ((TextBlock)(comment.BoxContent.Content)).Text = nome;
            
            if (animation)
            {
                cambioColoreAnimation(to, color);
            }
            else
            {
                barraColore.Width = to;
                ((SolidColorBrush)barraColore.Fill).Color=color;
            }
            
        }
        

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Image imageSender=(Image) sender;
            controller.risponde(imageSender.Name);
        }

        private void Value0_MouseEnter(object sender, MouseEventArgs e)
        {
            comment.Visibility = Visibility.Visible;
            Image imageSender = (Image)sender;
            ((TextBlock)(comment.BoxContent.Content)).Text = imageSender.Name;
            comment.AnchorPointY = ""+yValue[imageSender.Name];
        }

        private void Value0_MouseLeave(object sender, MouseEventArgs e)
        {
            Image imageSender = (Image)sender;
            ((TextBlock)(comment.BoxContent.Content)).Text = descrizioneValoreScelto;
            if (descrizioneValoreScelto.CompareTo("") != 0)
            {
                comment.AnchorPointY = "" + yScelto;

            }
            else
            {
                comment.Visibility = Visibility.Collapsed;
            }
        }

      
	}
}